package evs.identification;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import evs.brp.RemotingErrorException;
import evs.brp.ServerRequestHandler;

public class NameServer {
	
	private Log log = LogFactory.getLog(NameServer.class);
	
	public void printSyntax() {
		log.error("Syntax: NameServer PORT");
		System.exit(-1);
	}
	
	public static void main(String[] args) {
		
		NameServer testServer = new NameServer();
		int port = -1;
		
		if(args.length != 1) {
			testServer.printSyntax();
		} 
		else {
			try {
				port = new Integer(args[0]).intValue();
			}
			catch (Exception exc) {
				testServer.printSyntax();
			}
		}
		
		testServer.startServerRequestHandler(port);
	}
	
	public void startServerRequestHandler(int port) {
		
		try {
			log.info("STARTING EVS NAMESERVER");
			new NameServerRequestHandler(port);
		} 
		catch (RemotingErrorException exc) {
			log.error(exc);
		}
	}
}
